package com.s.remotelog.rpc;

import androidx.annotation.NonNull;

import s.log.Message;

public class RPCEvent implements Comparable<RPCEvent> {

    private Message msg;
    private Integer priority;
    private int index = 0;

    private RPCEvent(Message msg, EventPriority priority) {
        this.msg = msg;
        this.priority = priority.getPriority();
    }

    public static RPCEvent make(int level, String tag, String message) {
        return make(level, tag, message, EventPriority.NORMAL);
    }

    public static RPCEvent make(int level, String tag, String message, EventPriority priority) {
        Message msg = Message.newBuilder().setLevel(level).setTag(tag).setMsg(message).build();
        return new RPCEvent(msg, priority);
    }

    Message getMsg() {
        return msg;
    }

    int getIndex() {
        return index;
    }

    void setIndex(int index) {
        this.index = index;
    }

    @NonNull
    @Override
    public String toString() {
        return "RPCEvent , priority : " + priority + (msg == null ? "" : " status : " + msg.toString());
    }

    @Override
    public int compareTo(RPCEvent that) {
        return this.priority.compareTo(that.priority);
    }
}
